home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / mscheap2 / watch.c < prev   
C/C++ Source or Header  |  1990-03-07  |  1KB  |  44 lines

  1.         #include <stdio.h>
  2.  
  3.         #include <heap.h>
  4.  
  5.         //
  6.         //  Example of _heapwatch from heap.man
  7.         //
  8.  
  9.         void report( char *position );
  10.  
  11.         int main()
  12.         {
  13.         int index;
  14.  
  15.         char far *ptr = _fmalloc( 100 );
  16.  
  17.         for ( index=0 ; index<100 ; index++ )
  18.  
  19.             ptr[index] = (char) index;
  20.  
  21.         _fheapwatch( ptr, 1 );              // establishes the enty as read-only
  22.  
  23.         report( "read-only enabled" );      // should not detect an error
  24.  
  25.         ptr[0] = -1;                        // change part of the data
  26.  
  27.         report( "data modified" );          // should detect an error
  28.  
  29.         _fheapwatch( ptr, 0 );              // stop watching this region
  30.  
  31.         report( "read-only disabled" );     // should not detect an error
  32.  
  33.         return( 0 );
  34.         }
  35.  
  36.         void report( char *position )
  37.         {
  38.         int status = _fheapchk();
  39.  
  40.         printf( "Heap status after %s : %s\n", position, _heapstat(status) );
  41.         }
  42.  
  43.  
  44.